package com.zhitong.money.controller;

import com.zhitong.money.entity.AjaxResponse;
import com.zhitong.money.entity.ScheduleTime;
import com.zhitong.money.services.api.IScheduleTimeService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @Author: Andy Zhang
 * @Description:
 * @Date: 16:30 2021/3/17
 * @Company: wisecard
 */
@CrossOrigin
@RestController
public class ScheduleTimeContro {

    @Autowired
    private IScheduleTimeService scheduleTimeService;

    @GetMapping("/times")
    public AjaxResponse getAll() throws Exception{
        List<ScheduleTime> all = scheduleTimeService.getAll();
        return AjaxResponse.success(all);
    }

    @GetMapping("/time/{code}")
    public AjaxResponse getByCode(@PathVariable String code) throws Exception{
        return AjaxResponse.success(scheduleTimeService.getScheduleTimeByCode(code));
    }

    @RequiresPermissions({"updateTime"})
    @PutMapping("/time")
    public AjaxResponse update(@RequestBody Map<String,Object> map) throws Exception{

        scheduleTimeService.updateTimeByCode(map);
        return AjaxResponse.success("更新成功!");
    }
}
